%% delta = calcDelta(feature)
% feature: X-ROW Y-COLUMN
%   feature.value : M*N matrix
%   feature.xrange : [minX, maxX], WHERE maxX - minX + 1 = M
%   feature.yrange : [minY, maxY], WHERE maxY - minY + 1 = N
function delta = calcDelta(feature)
    [M,N] = size(feature.value);
    minX = feature.xrange(1,1);
    maxX = feature.xrange(1,2);
    minY = feature.yrange(1,1);
    maxY = feature.xrange(1,2);
    if ((maxX - minX + 1 ~= M) || (maxY - minY + 1 ~= N))
        ME = MException('calcDelta:feature', 'Matrix size does not match range values.');
        throw(ME);
    end
    sumY = sum(feature.value,1);
    sumX = sum(feature.value,2);
    sumAll = sum(sumY);
    %% calculate the value more accurately
%     pxy = feature.value / sumAll;
%     px = sumX / sumAll;
%     py = sumY / sumAll;
%     vxy = px*py;
%     delta = pxy-vxy;
    delta = (feature.value - sumX * sumY / sumAll)/sumAll;
end
